<?

class VsMailAccount {
	private static$_Instance = NULL;

	private $_imap = NULL;
	private $_error = '';

	static function Instance() {
		if(!self::$_Instance)
			self::$_Instance = &new VsAuth();

		return self::$_Instance;
	}
	//=================================================================

	function imap() { return $this->_imap; }
	function error() { return $this->_error; }
	//=================================================================

	function __destruct() {
		if($this->_imap)
			imap_close($this->_imap);
	}
	//=================================================================

	private function  __construct() {
		global $config;
	
		if(!is_array($config['mail'])) {
			$this->_error = "Database is not configured !";
		}
		else {
			$this->initNative();

		}

		$host = $config['mail']['host'];
		$port = $config['mail']['port'];
		$name = $config['mail']['name'];
		$user = $config['mail']['user'];
		$pass = $config['mail']['password'];
	
		if(!($this->_imap = imap_open("{".$host.":".$port."}".$name, $user, $pass))){
			$this->_error = imap_last_error();
		}
	}
	//=======================================================================

};

?>
